import 'package:flex_color_picker/flex_color_picker.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:ws2812_time/command/config.dart';
import 'package:ws2812_time/command/esp8266_iot.dart';

import 'logic.dart';

class PowerPage extends StatelessWidget {
  PowerPage({Key? key}) : super(key: key);

  final logic = Get.put(PowerLogic());

  @override
  Widget build(BuildContext context) {
    return Column(children: // Show the color picker in sized box in a raised card.
        [
      Obx(() {
        return Visibility(
          visible: Config.isOK.value,
          child: GestureDetector(
              onTap: () {
                logic.ledIsOFF.value = !logic.ledIsOFF.value;
                // Todo 发送 关闭LED时钟 请求
                //
              },
              child: SizedBox(
                width: 80,
                height: 80,
                child: Icon(
                  Icons.power_settings_new_rounded,
                  color: logic.ledIsOFF.value ? Colors.black : Colors.deepOrange,
                  size: 80,
                ),
              )),
        );
      }),
      Obx(() {
        return SizedBox(
          width: double.infinity,
          child: Padding(
            padding: const EdgeInsets.all(6),
            child: Card(
              elevation: 2,
              child: ColorPicker(
                // Use the screenPickerColor as start color.
                color: logic.screenPickerColor.value,
                // Update the screenPickerColor using the callback.
                onColorChanged: (Color color) => {
                  logic.screenPickerColor.value = color,
                },
                width: 44,
                height: 44,
                borderRadius: 22,
                heading: Text(
                  '更新颜色',
                  style: Theme.of(context).textTheme.headlineSmall,
                ),
                // TextButton(
                //   child: Text(
                //     '更新颜色',
                //     style: Theme.of(context).textTheme.headlineSmall,
                //   ),
                //   onPressed: () {
                //     ESP8266.setColor(logic.screenPickerColor.value);
                //   },
                // ),
              ),
            ),
          ),
        );
      }),
      Obx(() {
        return Text("亮度->${logic.brightness.value}");
      }),
      Obx(() {
        return Row(
          children: [
            const SizedBox(width: 20),
            Expanded(
              child: Slider(
                // 亮度滑块
                min: 0,
                // 0~255 太高 设置0~100
                max: 30,
                value: logic.brightness.value,
                divisions: 30,
                label: logic.brightness.value.toStringAsFixed(0),
                onChanged: (v) {
                  logic.brightness.value = v;
                },
                onChangeEnd: (v) {
                  logic.brightness.value = v;
                  ESP8266.setbright(v);
                },
              ),
            ),
            const SizedBox(width: 20),
          ],
        );
      }),
      const Text("末尾"),
    ]);
  }
}
